<?php
namespace App\Adshopuser\Controllers;
use Common\ControllerAdshopBase;

class CommonController extends ControllerAdshopBase
{

    public function initialize()
    {
        parent::initialize();
    }

    /**
     * 获取七牛token
     */
    public function getqntokenAction(){
        $token = $this->qiniu->get_token();
        $this->ok(['token' => $token]);
    }

    /**
     * 删除七牛图片
     */
    public function delQiniuAction()
    {
        if (!isset($this->params['key']) || empty($this->params['key'])) {
            $this->fail(-1, '缺少key');
        }
        if ($this->qiniu->qiniu_del($this->params['key'])) {
            $this->ok('操作成功!');
        } else {
            $this->fail(-1, '删除失败!');
        }
    }
    
    
    /**
     * 获取短信验证码
     */
    public function sms_codeAction(){
        if (!isset($this->params['phone']) || empty($this->params['phone'])) {
            $this->fail(-1, '手机号码不能为空');
        } else {
            if (!preg_match("/^1[3456789]{1}\d{9}$/", $this->params['phone'])) {
                $this->fail(-1, '手机号码错误');
            }
        }
        $code['code'] = rand(1000, 9999);
        $sms_result   = $this->jpush->sendMessage($this->params['phone'], $code);
        if ($sms_result['code']) {
            $resumt['msg_id'] = $sms_result['data'];
            $this->ok($resumt);
        } else {
            $this->fail(-1, $sms_result['msg']);
        }
    }

}
